<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title>HTML5 채팅 ver 1</title>
<script src="/js/html5/chat/jWebSocket.js" type="text/javascript"></script>
<script type="text/javascript">
	var ws;
	
	
	window.onload = function() {
		if( window.WebSocket == undefined ) {
			alert("WebSocket을 사용할 수 없습니다");
			return;
		}
		
		try {
			var host=jws.getServerURL( jws.JWS_SERVER_SCHEMA,
					jws.JWS_SERVER_HOST,
					80,
					jws.JWS_SERVER_CONTEXT,
					jws.JWS_SERVER_SERVLET );
			
			ws = new WebSocket(host);
			ws.onopen = function(event) {		log('접속 완료');  			};
			ws.onmessage = function(event) {	log('수신:' + event.data);	};
			ws.onclose = function(event) {		log('접속 종료');  			};
		}
		catch(e) {
			alert(e);
		}
	}
	
	function log(str) {
		var msg = document.getElementById('msg');
		msg.innerHTML = str + "<br />" + msg.innerHTML;
	}
	
	function sendLog() {
		var input_txt = document.getElementById("input_txt");
		ws.send( input_txt.value );
	}
</script>
</head>
<body>

<input type="text" size="14" id="input_txt" />
<input type="button" value="보내기" onclick="sendLog()" />
<div id="msg"></div>


</body>
</html>